package com.common.www.bean.entity.file;

//import com.bianmaba.realestate.bean.entity.authorization.UserRoleMiddle;

import com.common.www.MyApplicationListener;
import org.springframework.boot.base.jpa.domain.annotations.QueryCacheable;
import org.springframework.boot.base.jpa.domain.entity.NumberIdentityEntity;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

/**
 * 公共文件管理，包括视频图片文档等等
 *
 * @param
 * @author andyliu
 * @date 5/28/2018 4:23 PM
 * @return
 */
@DynamicUpdate(true)
@DynamicInsert(true)
@Entity
@Getter
@Setter
@QueryCacheable
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
@Table(name = "file_common")
@Builder
@AllArgsConstructor
@NoArgsConstructor
@ApiModel(value = "公共文件管理")
public class FileCommon extends NumberIdentityEntity {

    /**
     * 创建的用户
     */
    private String createUser;
    /**
     * 源名称
     */
    @Column(length = 512)
    @ApiModelProperty(value = "源名称")
    private String srcName;
    /**
     * 重命名后名称
     */
    @Column(length = 512)
    @ApiModelProperty(value = "重命名后名称")
    private String destName;
    /**
     * 模块名
     */
    @Column(length = 128)
    @ApiModelProperty(value = "模块名")
    private String moduleName;

    @ApiModelProperty(value = "1.图片2.gif 3.视频 ")
    private Integer type;


    /**
     * 绝对地址
     */
    @Column(length = 256)
    @ApiModelProperty(value = "绝对地址")
    private String absPath;
    /**
     * 下载绝对地址(不做保存，只是输出时实时计算)
     */
    @Column(length = 5000)
    @ApiModelProperty(value = "下载绝对地址")
    private String downloadPath;

    /**
     * 文件类型  file 图片，file文件，video视频
     */
    @Column(length = 32)
    @ApiModelProperty(value = "文件类型")
    private String fileType;

    /**
     * 文件宽度，图片、视频等文件才有此属性
     */
    @Column(length = 32)
    @ApiModelProperty(value = "文件宽度", example = "1")
    private Integer width;
    /**
     * 文件高度，图片、视频等文件才有此属性
     */
    @Column(length = 32)
    @ApiModelProperty(value = "文件高度", example = "1")
    private Integer height;
    /**
     * 文件大小
     */
    @Column(length = 32)
    @ApiModelProperty(value = "文件大小", example = "1")
    private Long size;

    @ApiModelProperty(value = "后缀")
    private String suffix;


    public String getDownloadPath() {
        return MyApplicationListener.publicProjectPath + absPath;
    }
}